package cn.tedu.cloudcar01.base.exception;

import cn.tedu.cloudcar01.base.response.JsonResult;
import cn.tedu.cloudcar01.base.response.StateCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

@RestControllerAdvice
public class GlobalHandleException {
    @ExceptionHandler
    public JsonResult doHandleConstraintViolationException(ConstraintViolationException e){
        String data = e.getMessage().split(":")[1].trim();
        return new JsonResult(StateCode.OPERATION_FAILED,data);
    }
}
